import {Component, OnInit} from '@angular/core';
import {JsonUtils} from 'great-jsutils'

@Component({
  selector: 'app-tool01',
  templateUrl: './tool01.component.html',
  styleUrls: ['./tool01.component.less']
})
export class Tool01Component implements OnInit {

  jsonStr = `{
    "name":"姓名",
    "age":"年龄"
  }`;
  html: string;

  constructor() {
  }

  ngOnInit() {
  }

  output() {
    if (this.jsonStr) {
      try {
        const json = JSON.parse(this.jsonStr);
        const code = JsonUtils.toClassModel(json);
        this.html = code.join('<br>');
      } catch (e) {
        this.html = 'json格式有误！';
      }
    } else {
      this.html = '内容不能为空！';
    }
  }

}
